package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.AssetPlatformAccount;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface AssetPlatformAccountMapper {
    @Delete({
        "delete from asset_platform_account",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into asset_platform_account (id, total_recharge_amount, ",
        "total_withdraw_coin, total_opex_coin, ",
        "update_time)",
        "values (#{id,jdbcType=BIGINT}, #{totalRechargeAmount,jdbcType=BIGINT}, ",
        "#{totalWithdrawCoin,jdbcType=BIGINT}, #{totalOpexCoin,jdbcType=BIGINT}, ",
        "#{updateTime,jdbcType=TIMESTAMP})"
    })
    int insert(AssetPlatformAccount record);

    int insertSelective(AssetPlatformAccount record);

    @Select({
        "select",
        "id, total_recharge_amount, total_withdraw_coin, total_opex_coin, update_time",
        "from asset_platform_account",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    AssetPlatformAccount selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(AssetPlatformAccount record);

    @Update({
        "update asset_platform_account",
        "set total_recharge_amount = #{totalRechargeAmount,jdbcType=BIGINT},",
          "total_withdraw_coin = #{totalWithdrawCoin,jdbcType=BIGINT},",
          "total_opex_coin = #{totalOpexCoin,jdbcType=BIGINT},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(AssetPlatformAccount record);

    /***********以下为自定义方法************************/

    // 充值：增加"充值金额"
    @Update({
            "update asset_platform_account",
            "set",
            "total_recharge_amount = total_recharge_amount + #{rechargeAmount,jdbcType=INTEGER}",
            "where id = 1"
    })
    int recharge(Integer rechargeAmount);

    @Update({
            "update asset_platform_account",
            "set",
            "total_opex_coin = total_opex_coin + #{coin,jdbcType=BIGINT}",
            "where id = 1"
    })
    int opex(Integer coin);

}